<?php
	class NewsAction extends Action{
		protected function _initialize(){
			define('RES', THEME_PATH . 'common');
		}
		
		public function index(){
			$article = M('New_article');
			if(empty($_GET['id'])){
				$id=$article->limit(1)->getField("id");
			}else{
				$id = $_GET['id'];
			}
			$count = $article->count('id');
		
			$page = new Page($count);
			$page->setConfig('theme','%upPage%%downPage%%first%%prePage%%linkPage%%nextPage%%end%');
			$show = $page->show();
			$list = $article->order('createtime desc')->limit($page->firstRow.','.$page->listRows)->field('id,title')->select();
			$this->assign('lists',$list);

			$this->assign('show',$show);
			if(isset($id)) {//防止数据库中一条数据也没有的情况
				$content=$article->where('id='.$id)->find();
			}
			$this->assign("article",$content);
			$this->display();
		}
		
		//--新闻列表显示页面暂时还是不要用了
		public function newslist(){
			$article = M('New_article');
			$count = $article->count("id");
			$page = new Page($count,15);
			$page->setConfig('theme','%totalRow% %header% %nowPage%/%totalPage% 页 %upPage% %downPage% %first% %prePage% %linkPage% %nextPage% %end%');
			$show = $page->show();
			$list = $article = M('New_article')->order('createtime desc')->limit($page->firstRow.','.$page->listRows)->select();
			$this->assign('lists',$list);
			$this->assign('show',$show);
			$this->display();
		}
	}